package com.googlecode.jot;

import java.lang.reflect.Type;

/**
 * An {@code TypeTranslator} is responsible for
 * translating objects from one type to another.
 *
 * @param <Foreign> the foreign type
 * @param <Local> the local type
 */
public interface TypeTranslator<Foreign, Local> {

	/**
	 * Translates the given local object to the given foreign object.
	 * @param local the local to convert from
	 * @param ctx the {@link TranslationContext}
	 * @param hints the TranslationHints
	 * @return the foreign
	 */
	Foreign translateFromLocal(Local local, TranslationContext ctx, TranslationHints hints);

	/**
	 * Translates the given foreign object to the given local object.
	 * @param object the object to convert from
	 * @param ctx the {@link TranslationContext}
	 * @param desiredType the desired local type
	 * @param hints the TranslationHints
	 * @return the local
	 */
	Local translateToLocal(Foreign object, TranslationContext ctx, Type desiredType, TranslationHints hints);

	/**
	 * Indicates whether or not the {@code TypeTranslator}
	 * supports the translation of the given {@link Type}.
	 * @param type the type
	 * @return true if able to - false otherwise
	 */
	boolean supportsLocal(Type type);
}
